// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.asset;

import java.io.InputStream;
import zombie.core.textures.ImageData;
import zombie.core.textures.TextureIDAssetManager;
import zombie.fileSystem.DeviceList;
import zombie.fileSystem.FileSystem;
import zombie.fileSystem.FileTask;
import zombie.fileSystem.IFileTaskCallback;

public final class FileTask_LoadPackImage extends FileTask {
    String m_pack_name;
    String m_image_name;
    boolean bMask;
    int m_flags;

    public FileTask_LoadPackImage(String packName, String imageName, FileSystem fs, IFileTaskCallback cb) {
        super(fs, cb);
        this.m_pack_name = packName;
        this.m_image_name = imageName;
        this.bMask = fs.getTexturePackAlpha(packName, imageName);
        this.m_flags = fs.getTexturePackFlags(packName);
    }

    @Override
    public void done() {
    }

    public Object call() throws Exception {
        TextureIDAssetManager.instance.waitFileTask();
        DeviceList deviceList = this.m_file_system.getTexturePackDevice(this.m_pack_name);
        InputStream inputStream = this.m_file_system.openStream(deviceList, this.m_image_name);

        ImageData imageData0;
        try {
            ImageData imageData1 = new ImageData(inputStream, this.bMask);
            if ((this.m_flags & 64) != 0) {
                imageData1.initMipMaps();
            }

            imageData0 = imageData1;
        } catch (Throwable throwable0) {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (Throwable throwable1) {
                    throwable0.addSuppressed(throwable1);
                }
            }

            throw throwable0;
        }

        if (inputStream != null) {
            inputStream.close();
        }

        return imageData0;
    }
}
